package com.tuanzi.loan.business.service.onekey.impl;

import com.tuanzi.loan.business.entity.onekey.CtrlOneKeyOnline;
import com.tuanzi.loan.business.repository.onekey.CtrlOneKeyOnlineRepository;
import com.tuanzi.loan.business.service.onekey.CtrlOneKeyOnlineService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.core.repository.JPAAuditRepository;
import com.tuanzi.loan.core.service.BaseAuditServiceImpl;
import com.tuanzi.loan.core.vo.PageSearcher;
import com.tuanzi.loan.vo.request.family.CtrlOneKeyOnlineRequest;
import com.tuanzi.loan.vo.response.family.CtrlOneKeyOnlineResponse;
import com.tuanzi.server.loan_base.constant.onekey.CtrlOneKeyOnlineConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.retry.RetryException;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author caiwanlin
 * @create 2018-07-12 11:50
 */
@Debug
@Service
@Transactional
@Retryable(value = { RetryException.class })
public class CtrlOneKeyOnlineServiceImpl extends BaseAuditServiceImpl<CtrlOneKeyOnline,Long> implements CtrlOneKeyOnlineService {
    @Autowired
    private CtrlOneKeyOnlineRepository ctrlOneKeyOnlineRepository;
    @Override
    protected JPAAuditRepository<CtrlOneKeyOnline, Long> getRepository() {
        return ctrlOneKeyOnlineRepository;
    }


    @Override
    public Page<CtrlOneKeyOnlineResponse> list(PageSearcher<CtrlOneKeyOnlineRequest> pageSearcher) {
        return ctrlOneKeyOnlineRepository.list(pageSearcher.getSearchCondition(),pageSearcher.getPageable());
    }

    @Override
    public void online(Long id) {
        CtrlOneKeyOnline ctrlOneKeyOnline = ctrlOneKeyOnlineRepository.findOne(id);
        ctrlOneKeyOnline.setStatus(CtrlOneKeyOnlineConfig.Status.ONLINE.index);
        saveOrUpdate(ctrlOneKeyOnline);
    }

    @Override
    public void offline(Long id) {
        CtrlOneKeyOnline ctrlOneKeyOnline = ctrlOneKeyOnlineRepository.findOne(id);
        ctrlOneKeyOnline.setStatus(CtrlOneKeyOnlineConfig.Status.OFFLINE.index);
        saveOrUpdate(ctrlOneKeyOnline);
    }
}
